/* ========================================================================== */
/*                                                                            */
/*   BoardTest.h                                                              */
/*   (c) 2001 Author                                                          */
/*                                                                            */
/*   Description                                                              */
/*                                                                            */
/* ========================================================================== */
#ifndef _BOAR_TEST_H_
#define _BOAR_TEST_H_

#include <csl.h>
#include <csl_emifa.h>
#include <csl_gpio.h>

//Global Definition
#define EVMDM642_CPLD_BASE    0x90080000

#define EVMDM642_FLASHPAGE    0x18

/* Read an 8-bit value from a CPLD register */
Uint8 EVMDM642_rget(Int16 regnum);
/* Write an 8-bit value to a CPLD register */
void EVMDM642_rset(Int16 regnum, Uint8 regval);
/* Spin in a delay loop for delay iterations */
void EVMDM642_wait(Uint32 delay);
/* Spin in a delay loop for delay microseconds */
void EVMDM642_waitusec(Uint32 delay);

void test_SCL();
void Start_I2c();
void Stop_I2c();
void  SendByte(unsigned char c);
unsigned char  RcvByte();
void Ack_I2c(unsigned char a);
unsigned char ISendByte(unsigned char sla,unsigned char c);
unsigned char ISendStr(unsigned char sla,unsigned char suba,unsigned char *s,unsigned char no);
unsigned char IRcvByte(unsigned char sla,unsigned char *c);
unsigned char IRcvStr(unsigned char sla,unsigned char suba,unsigned char *s,unsigned char no);
unsigned char ISendOneByte(unsigned char sla,unsigned char suba,unsigned char s);
unsigned char IRcvOneByte(unsigned char sla,unsigned char suba,unsigned char *s);

//Interface Definition
/*
EMIFA_Config DM642ConfigA={
	EMIFA_FMKS(GBLCTL,EK2RATE,HALFCLK)|
	EMIFA_FMKS(GBLCTL,EK2HZ,CLK)|
	EMIFA_FMKS(GBLCTL,EK2EN,ENABLE)|
	EMIFA_FMKS(GBLCTL,EK2EN,ENABLE)|
}
*/
//SDRAM Testing
/*
 *  Memory functions
 */
void HY57V283220_SDRAM_Test();
 
Int16 MEM_fill(Uint32 start, Uint32 len, Uint32 val);
Int16 MEM_addr(Uint32 start, Uint32 len);
Int16 MEM_addrInv(Uint32 start, Uint32 len);
Int16 MEM_walking(Uint32 add);
Int16 MEM_bytestrobe(Uint32 add);
Int16 MEM_test(Uint32 start, Uint32 len, Int16 patterntype);
Int16 TEST_intMem();
Int16 TEST_extMem();

/* Flash address definitions */
#define EVMDM642_FLASH_BASE          0x90000000
#define EVMDM642_FLASH_SECTORSIZE    0x010000
#define EVMDM642_FLASH_SECTORS       0x8
#define EVMDM642_FLASH_PAGES         0x8
#define EVMDM642_FLASH_PAGESIZE      0x080000
#define EVMDM642_FLASH_SIZE          0x400000
#define EVMDM642_FLASH_CTL555        (EVMDM642_FLASH_BASE + 0x555)
#define EVMDM642_FLASH_CTLAAA        (EVMDM642_FLASH_BASE + 0xaaa)
#define EVMDM642_FLASH_SUPPORT       1
 
/* Calculate the checksum of a data range in Flash */
Uint32 EVMDM642_FLASH_checksum(Uint32 start, Uint32 length);

/* Erase a segment of Flash memory */
void EVMDM642_FLASH_erase(Uint32 start, Uint32 length);

/* Read data from a range in Flash */
void EVMDM642_FLASH_read(Uint32 src, Uint32 dst, Uint32 length);

/* Write data to a data range in Flash */
void EVMDM642_FLASH_write(Uint32 src, Uint32 dst, Uint32 length);

//UART
#define EVMDM642_UART_CONFIGREGS      4
#define EVMDM642_UART_BASEADDR        0x9c00
#define EVMDM642_UART_RBR             0x00  // Read
#define EVMDM642_UART_THR             0x00  // Write
#define EVMDM642_UART_IER             0x01
#define EVMDM642_UART_IIR             0x02  // Read
#define EVMDM642_UART_FCR             0x02  // Write
#define EVMDM642_UART_LCR             0x03
#define EVMDM642_UART_MCR             0x04
#define EVMDM642_UART_LSR             0x05
#define EVMDM642_UART_SCR             0x07

#define EVMDM642_UART_DLL             0x08
#define EVMDM642_UART_DLH             0x09
#define EVMDM642_UART_EFR             0x0A
#define EVMDM642_UART_XON1            0x0C
#define EVMDM642_UART_XON2            0x0D
#define EVMDM642_UART_XOFF1           0x0E
#define EVMDM642_UART_XOFF2           0x0F

#define EVMDM642_UART_TCR             0x16
#define EVMDM642_UART_TLR             0x17

#define EVMDM642_UART_FIFORDY         0x1f

#define EVMDM642_UARTA                0
#define EVMDM642_UARTB                1

#define EVMDM642_UART_BAUD115200     0x010
#define EVMDM642_UART_BAUD57600      0x020
#define EVMDM642_UART_BAUD38400      0x030
#define EVMDM642_UART_BAUD19200      0x060
#define EVMDM642_UART_BAUD9600       0x0c0
#define EVMDM642_UART_BAUD4800       0x180
#define EVMDM642_UART_BAUD2400       0x300
#define EVMDM642_UART_BAUD1200       0x600

/* UART handle */
typedef Int16 EVMDM642_UART_Handle;

/* Config structure for the EVMDM642 UART */
typedef struct EVMDM642_UART_Config {
    int regs[EVMDM642_UART_CONFIGREGS];
} EVMDM642_UART_Config;

/* Set a UART register */
extern void EVMDM642_UART_rset(EVMDM642_UART_Handle hUart, Int16 regnum, Int16 regval);

/* Get the value of a UART register */
extern Int16 EVMDM642_UART_rget(EVMDM642_UART_Handle hUart, Int16 regnum);

/* Initialize UART and return handle */
extern Int16 EVMDM642_UART_open(Int16 devid, Int16 baudrate, EVMDM642_UART_Config *Config);

/* Get one character of data from the UART */
extern Int16 EVMDM642_UART_getChar(EVMDM642_UART_Handle hUart);

/* Send one character of data to the UART */
extern void EVMDM642_UART_putChar(EVMDM642_UART_Handle hUart, Uint16 data);

#endif //_BOAR_TEST_H_
